param ([string] $configFile, [string] $outputFile,  [switch] $debug, [switch] $help)


function usage() {
	Write-Host "IQTools.ps1 -configFile <fileName> -outputFile <Absolutefilename> [-debug] [-help]"
	Write-Host "IQTools.ps1 -configFile <fileName> [-debug] [-help]"
	Write-Host "this tools is able to generate  a list of software/file"
	Write-Host "-debug : display additional message"
	Write-Host "-help  : display usage of the function"
}

function fail ([string] $message) {
	Write-ERROR "There was an error ...." 
	Write-ERROR "$message" 
	Write-HOST "error ... please look at the usage"
	usage
	exit 1
}	

Write-Host "	<IQTools.ps1>  Copyright (C) 2012  Laurent.Tardif (laurent.tardif@persistentsas.com)"
Write-Host ""
Write-Host "    This program comes with ABSOLUTELY NO WARRANTY; for details see the copyrith.txt file."
Write-Host "    This is free software, and you are welcome to redistribute it"
Write-Host "    under certain conditions; Read the copyrith.txt file for details."


if ( $help ) {
	usage
	exit 3
}

if([String]::IsNullOrEmpty($configFile))
{
		fail "The configFile element was not provided as parameter"
} 

if([String]::IsNullOrEmpty($outputFile))
{
		fail "The outputfilename element was not provided as parameter"
} 
	
function generateHashCode([string] $pFile) {
	$file=resolve-path $pFile
	#TODO : may be the algo can be shared during all analysis
	$algo = [System.Security.Cryptography.HashAlgorithm]::Create("MD5")
	#Take care to open the file in readonly mode
	$stream = New-Object System.IO.FileStream($file, [System.IO.FileMode]::Open,[System.IO.FileAccess]::Read)
	$md5StringBuilder = New-Object System.Text.StringBuilder
	$algo.ComputeHash($stream) | % { [void] $md5StringBuilder.Append($_.ToString("x2")) }
	$stream.Dispose()	
	#This is the output
	return $md5StringBuilder.ToString()
}

function writeIQFileHeader([string] $pFile) {
	$version=$soft."IQToolsSetup"
	Write-Output "<IQCheck version='$version'>" | out-file -enc ascii $pFile
	$currentDate=Get-Date
	
	$myIp=(@(gwmi Win32_NetworkAdapterConfiguration | ? { $_.IPAddress -ne $null }))[0].IPAddress;
	$myhostname=hostname
	
	Write-Output "  <META>" | out-file -enc ascii $pFile -append
	Write-Output "    <Date>$currentDate</Date>" | out-file -enc ascii $pFile -append
	Write-Output "    <Version>$version</Version>" | out-file -enc ascii $pFile -append
	Write-Output "    <IP>$myIp</IP>" | out-file -enc ascii $pFile -append
	Write-Output "    <Hostname>$myhostname</Hostname>" | out-file -enc ascii $pFile -append
	Write-Output "  </META>" | out-file -enc ascii $pFile -append
}

# #######################################################################
#
# Write the hardware parameters in the file
#
# #######################################################################
function WriteHardwareSection([string] $pFile, [System.Xml.Linq.XContainer] $hardware) {
	Write-Output "  <hardware>" | out-file -enc ascii $pFile -append
	if ($debug) { Write-Host  "------------------ Working on hardware "  }

	foreach ($hardwareParam in $hardware.Elements() ) {
		#get the attribute 
		$nameAtt=$hardwareParam.Name;
		if ($nameAtt -eq $null ) {
			# Write-Host "No attribut for hardware"
		} elseif ($nameAtt -eq "memory" ) {
			#Write-Host "memory is required"
            $mem = Get-WmiObject -Class Win32_ComputerSystem
			Write-Output "    <memory>$($mem.TotalPhysicalMemory/1mb) MB</memory>" | out-file -enc ascii $pFile -append
        } elseif ($nameAtt -eq "cpu" ) {
			#Write-Host "cpu is required"
            $processors = $env:NUMBER_OF_PROCESSORS
			Write-Output "    <cpu>$processors</cpu>" | out-file -enc ascii $pFile -append
        } elseif ($nameAtt -eq "disks" ) {
			#Write-Host "disks is required"
			WriteDiskSection $pFile
		}
        else {
            fail "Unknown attribut ($nameAtt) for hardware)"
		}
	}
	
	Write-Output "  </hardware>" | out-file -enc ascii $pFile -append
}

# #######################################################################
#
# Write the disks parameters in the file
#
# #######################################################################

function WriteDiskSection([string] $pFile) {
	
	#Get List of disks
	$disks=getListOfDisk
	
	#Write list of disks
	Write-Output "    <disks>" | out-file -enc ascii $pFile -append
	if ($debug) { Write-Host  "---------------------- Working on disks "  }

	$keys=$disks.keys |sort 
	foreach ($key in $keys) {
		$encodedkey=[system.web.httputility]::htmlencode($key)
		Write-Output "        <Disk>" | out-file -enc ascii $pFile -append
		Write-Output "    		  <name>$encodedkey</name>" | out-file -enc ascii $pFile -append
		$unit=" GB"
		if (($($disks.$key).ToString()).StartsWith("SIZE NOT FOUND")) {
			$unit=""
		}
		Write-Output "    		  <size>$($disks.$key)$unit</size>" | out-file -enc ascii $pFile -append
		Write-Output "        </Disk>" | out-file -enc ascii $pFile -append
	}
	
	Write-Output "    </disks>" | out-file -enc ascii $pFile -append
}


# #######################################################################
#
# Write the list of Operating System in the file
#
# #######################################################################
function WriteOperatingSystemSection([string] $pFile) {


	$operatingSystem=get-wmiobject Win32_OperatingSystem
	Write-Output "  <OperatingSystem>" | out-file -enc ascii $pFile -append
	Write-Output "    <Name>$($operatingSystem.Name)</Name>" | out-file -enc ascii $pFile -append
	Write-Output "    <Caption>$($operatingSystem.Caption)</Caption>" | out-file -enc ascii $pFile -append
	Write-Output "    <OSArchitecture>$($operatingSystem.OSArchitecture)</OSArchitecture>" | out-file -enc ascii $pFile -append
	Write-Output "    <OSType>$($operatingSystem.OSType)</OSType>" | out-file -enc ascii $pFile -append
	Write-Output "    <SystemDirectory>$($operatingSystem.SystemDirectory)</SystemDirectory>" | out-file -enc ascii $pFile -append
	Write-Output "    <Version>$($operatingSystem.Version)</Version>" | out-file -enc ascii $pFile -append				
	Write-Output "    <BuildNumber>$($operatingSystem.BuildNumber)</BuildNumber>" | out-file -enc ascii $pFile -append
	Write-Output "    <ServicePackMajorVersion>$($operatingSystem.ServicePackMajorVersion)</ServicePackMajorVersion>" | out-file -enc ascii $pFile -append
	Write-Output "    <ServicePackMinorVersion>$($operatingSystem.ServicePackMinorVersion)</ServicePackMinorVersion>" | out-file -enc ascii $pFile -append	
	Write-Output "    <RegisteredUser>$($operatingSystem.RegisteredUser)</RegisteredUser>" | out-file -enc ascii $pFile -append
	Write-Output "    <Organization>$($operatingSystem.Organization)</Organization>" | out-file -enc ascii $pFile -append
	Write-Output "    <SerialNumber>$($operatingSystem.SerialNumber)</SerialNumber>" | out-file -enc ascii $pFile -append		

	Write-Output "    <OSLanguage>$($operatingSystem.OSLanguage)</OSLanguage>" | out-file -enc ascii $pFile -append			
	Write-Output "    <MUILanguages>$($operatingSystem.MUILanguages)</MUILanguages>" | out-file -enc ascii $pFile -append			
	Write-Output "    <Locale>$($operatingSystem.Locale)</Locale>" | out-file -enc ascii $pFile -append			
	Write-Output "    <CountryCode>$($operatingSystem.CountryCode)</CountryCode>" | out-file -enc ascii $pFile -append		
	Write-Output "  </OperatingSystem>" | out-file -enc ascii $pFile -append
}


# #######################################################################
#
# Write the list of software in the file
#
# #######################################################################
function WriteSoftSection([string] $pFile, [hashtable] $softwares) {
	$size=$softwares.Count
	if ($debug) {
		Write-Host "Size of software : size is $size " 
	}
	Write-Output "  <Softwares length=`"$size`">" | out-file -enc ascii $pFile -append
	$keys=$softwares.keys |sort 
	foreach ($key in $keys) {
		$encodedkey=[system.web.httputility]::htmlencode($key)
		Write-Output "    <Software>" | out-file -enc ascii $pFile -append
		Write-Output "    		<name>$encodedkey</name>" | out-file -enc ascii $pFile -append
		Write-Output "    		<version>$($softwares.$key)</version>" | out-file -enc ascii $pFile -append
		Write-Output "    </Software>" | out-file -enc ascii $pFile -append
	}
	Write-Output "  </Softwares>" | out-file -enc ascii $pFile -append
}

# #######################################################################
#
# Write the list of hotfixes in the file
#
# #######################################################################
function WriteHotFixesSection([string] $pFile, [hashtable] $hotFixes) {
	$size=$hotFixes.Count
	if ($debug) {
		Write-Host "Size of hotfixe : size is $size " 
	}
	Write-Output "  <hotfixes length=`"$size`">" | out-file -enc ascii $pFile -append
	$keys=$hotFixes.keys |sort 
	foreach ($key in $keys) {
		$encodedkey=[system.web.httputility]::htmlencode($key)
		Write-Output "    <hotfixe>" | out-file -enc ascii $pFile -append
		Write-Output "    		<name>$encodedkey</name>" | out-file -enc ascii $pFile -append
		Write-Output "    		<version>$($hotFixes.$key)</version>" | out-file -enc ascii $pFile -append
		Write-Output "    </hotfixe>" | out-file -enc ascii $pFile -append
	}
	Write-Output "  </hotfixes>" | out-file -enc ascii $pFile -append
}

# #######################################################################
#
# Write the server ID attributs in the file
#
# #######################################################################
function WriteServerIdSection([string] $pFile, [System.Xml.Linq.XContainer] $serverId) {
	Write-Output "  <serverId>" | out-file -enc ascii $pFile -append
	if ($debug) { Write-Host  "------------------ Working on serverId "  }

	foreach ($serverIdParam in $serverId.Elements() ) {
		#get the attribute 
		$nameAtt=$serverIdParam.Name;
		if ($nameAtt -eq $null ) {
			# Write-Host "No attribut for serverID"
		} elseif ($nameAtt -eq "name" ) {
			# Write-Host "Name is required"
			if ($debug) { Write-Host "name is : $($env:COMPUTERNAME)" }
			Write-Output "    <name>$($env:COMPUTERNAME)</name>" | out-file -enc ascii $pFile -append
        } elseif ($nameAtt -eq "domain" ) {
			# Write-Host "Domain is required"
			if ($debug) { Write-Host "domain is : $($env:USERDNSDOMAIN)" }
			Write-Output "    <domain>$($env:USERDNSDOMAIN)</domain>" | out-file -enc ascii $pFile -append
        }
        else {
            fail "Unknown attribut ($nameAtt) for serverId)"
		}
	}
	
	Write-Output "  </serverId>" | out-file -enc ascii $pFile -append
}


# #######################################################################
#
# Write the list of services in the file
#
# #######################################################################
function WriteServicesSection([string] $pFile, [hashtable] $services) {
	$size=$services.Count
	if ($debug) {
		Write-Host "Size of services : size is $size " 
	}
	Write-Output "  <Services length=`"$size`">" | out-file -enc ascii $pFile -append
	$keys=$services.keys |sort 
	foreach ($key in $keys) {
		$encodedkey=[system.web.httputility]::htmlencode($key)
		Write-Output "    <Service>" | out-file -enc ascii $pFile -append
		Write-Output "    		<name>$encodedkey</name>" | out-file -enc ascii $pFile -append
		Write-Output "    		<status>$($services.$key)</status>" | out-file -enc ascii $pFile -append
		Write-Output "    </Service>" | out-file -enc ascii $pFile -append
	}
	Write-Output "  </Services>" | out-file -enc ascii $pFile -append
}


# #######################################################################
#
# Write the list of environment variables in the file
#
# #######################################################################
function WriteEnvironmentSection([string] $pFile, [hashtable] $envVariables) {
	$size=$envVariables.Count
	if ($debug) {
		Write-Host "Size of envVariables : size is $size " 
	}
	Write-Output "  <Environment length=`"$size`">" | out-file -enc ascii $pFile -append
	$keys=$envVariables.keys |sort 
	foreach ($key in $keys) {
		Write-Output "    <Variable>" | out-file -enc ascii $pFile -append
		Write-Output "    		<name>$key</name>" | out-file -enc ascii $pFile -append
		Write-Output "    		<value>$($envVariables.$key)</value>" | out-file -enc ascii $pFile -append
		Write-Output "    </Variable>" | out-file -enc ascii $pFile -append
	}
	Write-Output "  </Environment>" | out-file -enc ascii $pFile -append
}



function WriteFileSection([string] $pFile, [System.Xml.Linq.XContainer] $directories) {
	Write-Output "  <directories>" | out-file -enc ascii $pFile -append
	$directoriesSorted=$directories.Elements()  |sort
	
	foreach ($directory in $directoriesSorted ) {
		if ($debug) { Write-Host  "------------------ Working on a directory "  }
		Write-Output "    <directory>" | out-file -enc ascii $pFile -append
		#get the name attribute 
		$dirname=$directory.Attribute("Name").Value
		$pattern=$directory.Attribute("Pattern").Value
		if ($debug) {Write-Host "  Name = $dirname , pattern=$pattern"}
		Write-Output "    <attributes><Name>$dirname</Name><pattern>$pattern</pattern></attributes>" | out-file -enc ascii $pFile -append
		#Write-Host "get-ChildItem $dirname\$pattern -recurse "
		
		#IF DIRECTORY DID NOT EXIST ... ERROR .... Test-PATH ? 
		$listOfFiles=@(get-ChildItem $dirname\$pattern -recurse |sort )
		if ($debug) { Write-Host "  We have found $($listOfFiles.Length) elements" }
	
		#Now get the list of action to do on these files
		$actions=$directory.Element("actions")
		
		if([String]::IsNullOrEmpty($actions)) {
			fail "No action have been defined in the directory ($dirname) element with pattern ($pattern)"
		}		
		$name=$actions.Element("name");
		$extract=$actions.Element("extract");
		$checksum=$actions.Element("checksum");
		$version=$actions.Element("version");
		Write-Output "      <files>" | out-file -enc ascii $pFile -append
		foreach ($file in $listOfFiles) {
			Write-Output "        <file>" | out-file -enc ascii $pFile -append
			if ($name -eq $null ) {
				#Write-Host "No name required"
			} else {
				#Write-Host "Name is required"
				if ($debug) { Write-Host "file is : $($file.fullname)" }
				Write-Output "          <name>$($file.fullname)</name>" | out-file -enc ascii $pFile -append
			}
			
			
			if ($extract -eq $null ) {
				#Write-Host "No extract required"
			} else {
				#Write-Host "Extract required"
				$fields=$extract.Elements("field")
				$content=get-content $file.fullname
				Write-Output "          <extracted>" | out-file -enc ascii $pFile -append
				foreach ($field in $fields) {
					$data=$content | select-string $field.Value
					$encodeddata=[system.web.httputility]::htmlencode($data)
					if ($debug) { Write-Host "  EXTRACTED : $($field.Value) => $data" }
					Write-Output "            <$($field.Value)>$encodeddata</$($field.Value)>" | out-file -enc ascii $pFile -append
				}
				Write-Output "          </extracted>" | out-file -enc ascii $pFile -append
			}
			
			
			if ($checksum -eq $null ) {
				#Write-Host "No checksum required"
			} else {
				if ($debug) { Write-Host "Checksum is required" }
				$value=generateHashCode $file.fullname
				if ($debug) { Write-Host "checksum of : $file, is $value" }
				Write-Output "          <checksum>$value</checksum>" | out-file -enc ascii $pFile -append
			}  #if 
			
			
			if ($version -eq $null ) {
				#Write-Host "No Version required"
			} else {
				if ($debug) { Write-Host "Version is required" }
				$value=$file.VersionInfo.FileVersion
				$value=$file.VersionInfo.ProductVersion
				if ($debug) { Write-Host "Version of : $file, is $value" }
				Write-Output "          <Versions>"| out-file -enc ascii $pFile -append
				Write-Output "            <FileVersion>$($file.VersionInfo.FileVersion)</FileVersion>"| out-file -enc ascii $pFile -append
				Write-Output "            <ProductVersion>$($file.VersionInfo.ProductVersion)</ProductVersion>"| out-file -enc ascii $pFile -append
				Write-Output "          </Versions>" | out-file -enc ascii $pFile -append
			}
			
			Write-Output "        </file>" | out-file -enc ascii $pFile -append
		} #for each file
		Write-Output "    </files>" | out-file -enc ascii $pFile -append
		Write-Output "  </directory>" | out-file -enc ascii $pFile -append
	} #for each directory
	
	Write-Output "  </directories>" | out-file -enc ascii $pFile -append
}

function WriteIQFileFooter([string] $pFile) {
	Write-Output "</IQCheck>" | out-file -enc ascii $pFile -append
}
	
	
# #######################################################################
#
# Get the list of software registered on the local PC, return a 
# hash, with the list of soft as key, and the version as value
#
# #######################################################################
function getListOfSoft () {
	$computer="localhost"
	$programs_installed = @{};
	if ($debug) {
		Write-Host "collecting list of sofware"
	}
	
	#no need to sort the list, has we'll work on a hashtable ..; we need to sort the keys.
	
	#buggy way, collect only soft installed with msiexec
	#$win32_product = @(get-wmiobject -class 'Win32_Product' -computer $computer );
	
	#TIP provided by Seb Duff and updated by LT 
	#collect first all the software 32bits 
	$products = @(Get-ChildItem 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall')
	
	if (Test-Path  'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall') {
		#we are in 64bits mode
		$win64_product = @(Get-ChildItem 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall')
		$products=$products + $win64_product
	}
	
	foreach ($product in $products) {
		$name =  $product.getValue("DisplayName");
		$version = $product.getValue("DisplayVersion");
		if ($name -ne $null) {
			if ([String]::IsNullOrEmpty($version)) {
				$programs_installed.$name = "UNKNOWN";
			} else {
				$programs_installed.$name = $version;
			}
		}
	}
	return $programs_installed
}

	
# #######################################################################
#
# Get the list of services registered on the local PC, return a 
# hash, with the list of soft as key, and the status as value
#
# #######################################################################
function getListOfServices () {
	$services_installed = @{};
	if ($debug) {
		Write-Host "collecting list of services"
	}
	#no need to sort the list, has we'll work on a hashtable ..; we need to sort the keys.
	$services = @(get-service);
	foreach ($service in $services) {
		$name = $service.DisplayName;
		$Status = $service.Status;
		if ($name -ne $null) {
			if ([String]::IsNullOrEmpty($Status)) {
				$services_installed.$name = "UNKNOWN";
			} else {
				$services_installed.$name = $Status;
			}
		}
	}
	return $services_installed
}

# #######################################################################
#
# Get the list of hotfixes registered on the local PC, return a 
# hash, with the list of hotfixes as ........   , and 
#
# #######################################################################

function getListOfHotfixes () {
	$hotfixes_applied=@{};
	if ($debug) {
		Write-Host "collecting list of hotfixes"
	}
	#no need to sort the list, has we'll work on a hashtable ..; we need to sort the keys.
	$hotfixes = @(Get-HotFix);
	foreach ($hotfixe in $hotfixes) {
		if ($hotfixe.HotFixId -eq "File 1")
		{
			# On Win XP, Get-hotfix cmd return also previous system patches under "file 1" name (obsolete hotfix id is found in ServicePackInEffect parameter) 
			$id="obsolete_$($hotfixe.ServicePackInEffect)";
            $Description="obsoleted by $($hotfixe.ServicePackInEffect)";
		}
		else
		{
			$id=$hotfixe.HotFixId;
			$Description=$hotfixe.Description;
		}
		if ($id -ne $null) {
			if ([String]::IsNullOrEmpty($Description)) {
				$hotfixes_applied.$id = "UNKNOWN";
			} else {
				$hotfixes_applied.$id = $Description;
			}
			if ($debug) {
				Write-Host "hotfixes found is : id was ($id) description was ($Description);"
			}
		}
	}
	return $hotfixes_applied
}


# #######################################################################
#
# Get the list of disk registered on the local PC, return a 
# hash, with the list of disk name as key, and the size as value
#
# #######################################################################
function getListOfDisk () {
	$disks = @{};
	if ($debug) { Write-Host "collecting list of disk" }
	
	$logicalDisks=Get-WmiObject -class Win32_logicaldisk
	foreach ($disk in $logicalDisks) {
		#$deviceID = $disk.DeviceID => C:
		$name = $disk.DeviceID + $disk.VolumeName		
		$size = [Math]::Round($disk.size/1gb)
		if ($debug) { Write-Host "collecting size of disk ($name) :$($disk.size) in GB will be ($size)"}
		if ($name -ne $null) {
				if (($size -ne $null) -and ($size -ne 0)) {
					$disks.$name = $size;
				} else {
					$disks.$name = "SIZE NOT FOUND (acceptable if CD or DVD drives)";
				}		
		} elseif ($size -ne $null) {
				$disks."NONAMEONDISK"= $size;
			} else {
				$disks."NONAMEONDISK" = "SIZE NOT FOUND";
		}
		
	}
	return $disks
}

	
# #######################################################################
#
# Get the list of Environement variables registered on the local PC, return a 
# hash, with the list of variables as key, and the version as value
#
# #######################################################################
function getListOfEnvironmentVariables () {
	$variable_defined = @{};
	if ($debug) {
		Write-Host "collecting Environement variables"
	}
	
	#no need to sort the list, has we'll work on a hashtable ..; we need to sort the keys.
	$variables = @(Get-ChildItem Env:);
	foreach ($variable in $variables) {
		$name = $variable.Name;
		$value = $variable.Value;
		if ($name -ne $null) {
			$variable_defined.$name = $value;
		}
	}
	return $variable_defined
}


# -----------------------------------------------------------------------
#
#   BEGIN OF ANALYSE / HEADER
#
# -----------------------------------------------------------------------

$configFile=resolve-path $configFile
$outputFile=$outputFile

[Reflection.Assembly]::LoadWithPartialName("System.Xml.Linq") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("System.web") | Out-Null

$doc = [Xml.Linq.XDocument]::Load($configFile)

#we get all the time the list of soft, to know the version of the IQTOOLS
#we need it before writing the header
$soft=getListOfSoft


#generating the header
writeIQFileHeader $outputFile

# -----------------------------------------------------------------------
#
#   OS SECTION 
#
# -----------------------------------------------------------------------
$operatingSystem = $doc.Element("IQTOOLS").Element("OS")
if([String]::IsNullOrEmpty($operatingSystem))
{
		#do not compute operatingSystem
}   
else 
{
	#Generate the operatingSystem section
	WriteOperatingSystemSection  "$outputFile" 
}


# -----------------------------------------------------------------------
#
#   SOFTWARE SECTION 
#
# -----------------------------------------------------------------------
$software = $doc.Element("IQTOOLS").Element("software")

if([String]::IsNullOrEmpty($software))
{
		#do not compute sofware
}   
else 
{
	#Generate the sofware section
	#$soft=getListOfSoft
	WriteSoftSection  "$outputFile" $soft
}

# -----------------------------------------------------------------------
#
#   SERVICES SECTION 
#
# -----------------------------------------------------------------------
$services = $doc.Element("IQTOOLS").Element("services")
if([String]::IsNullOrEmpty($services))
{
		#do not compute services
}   
else 
{
	#Generate the services section
	$servicesList=getListOfServices
	WriteServicesSection  "$outputFile" $servicesList
}

# -----------------------------------------------------------------------
#
#   Network SECTION 
#
# -----------------------------------------------------------------------
$network = $doc.Element("IQTOOLS").Element("network")
if([String]::IsNullOrEmpty($network))
{
		#do not compute network
}   
else 
{
	#Generate the network section
	$networkHash=getListOfNetworks $network
	WriteNetworkSection  "$outputFile" $networkHash
}


# -----------------------------------------------------------------------
#
#   HOTFIXES SECTION 
#
# -----------------------------------------------------------------------
$hotfixes = $doc.Element("IQTOOLS").Element("hotfixes")
if([String]::IsNullOrEmpty($hotfixes))
{
		#do not compute hotfixes
}   
else 
{
	#Generate the hotfixes section
	$hotFixesList=getListOfHotfixes
	WriteHotFixesSection  "$outputFile" $hotFixesList
}

# -----------------------------------------------------------------------
#
#   SERVEURID SECTION 
#
# -----------------------------------------------------------------------
$serverId = $doc.Element("IQTOOLS").Element("serverId")
if([String]::IsNullOrEmpty($serverId))
{
		#do not compute serverId
}   
else 
{
	#Generate the server Id section
	WriteServerIdSection  "$outputFile" $serverId
}

# -----------------------------------------------------------------------
#
#   HARDWARE SECTION 
#
# -----------------------------------------------------------------------
$hardware = $doc.Element("IQTOOLS").Element("hardware")
if([String]::IsNullOrEmpty($hardware))
{
		#do not compute hardware
}   
else 
{
	#Generate the hardware section
	WriteHardwareSection  "$outputFile" $hardware
}

# -----------------------------------------------------------------------
#
#   Environment SECTION 
#
# -----------------------------------------------------------------------
$environment = $doc.Element("IQTOOLS").Element("environment")
if([String]::IsNullOrEmpty($environment))
{
		#do not compute environment
}   
else 
{
	#Generate the Environement section
	$environementVariables=getListOfEnvironmentVariables
	WriteEnvironmentSection  "$outputFile" $environementVariables
}



# -----------------------------------------------------------------------
#
#   Directories SECTION 
#
# -----------------------------------------------------------------------
#Generate the directories section
$directories = $doc.Element("IQTOOLS").Element("directories")
if([String]::IsNullOrEmpty($directories))
{
	#do not compute directories
}   
else 
{
	WriteFileSection  "$outputFile" $directories
}


# -----------------------------------------------------------------------
#
#   ENF OF ANALYSE / FOOTER
#
# -----------------------------------------------------------------------

#Writing the footer
WriteIQFileFooter $outputFile
